package com.zscat.mallplus.finance.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zscat.mallplus.annotation.SysAdminOperLog;
import com.zscat.mallplus.finance.entity.FinanceCheckAccount;
import com.zscat.mallplus.finance.entity.FinanceSettlement;
import com.zscat.mallplus.finance.mapper.FinanceCheckAccountMapper;
import com.zscat.mallplus.finance.service.IFinanceCheckAccountService;
import com.zscat.mallplus.finance.service.IFinanceOrderStatisticService;
import com.zscat.mallplus.finance.service.IFinanceSettlementService;
import com.zscat.mallplus.finance.vo.CheckAmountDetailInfo;
import com.zscat.mallplus.oms.entity.OmsOrder;
import com.zscat.mallplus.oms.service.IOmsOrderService;
import com.zscat.mallplus.utils.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author loop.fu
 * @since 2020-03-10
 */
@RestController
@RequestMapping("/finance/financeSettlementV1")
public class FinanceSettlementController {
    @Resource
    private IFinanceSettlementService financeSettlementService;

    @Resource
    private IFinanceCheckAccountService financeCheckAccountService;

    /**
     * 结算列表
     *
     * @param entity
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/financeSettlementList")
    public Object financeSettlementList(FinanceSettlement entity,
                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        try {
            return new CommonResult().success(financeSettlementService.page(new Page<>(pageNum, pageSize), new QueryWrapper<>(entity)));
        } catch (Exception e) {
            e.printStackTrace();
            return new CommonResult().failed();
        }
    }

    /**
     * 确认账单
     *
     * @return
     */
    @GetMapping(value = "/confirmSettlement")
    public Object confirmSettlement(Long id) {
        try {
            FinanceSettlement financeSettlement = financeSettlementService.getById(id);
            financeSettlement.setStatus(1);
            financeSettlementService.updateById(financeSettlement);
            return new CommonResult().success();
        } catch (Exception e) {
            e.printStackTrace();
            return new CommonResult().failed();
        }

    }

    /**
     * 获取对账单信息
     *
     * @return
     */
    @GetMapping(value = "/checkAmountDetail")
    public Object checkAmountDetail(Long settlementId) {
        try {
            CheckAmountDetailInfo checkAmountDetailInfo = financeSettlementService.getCheckAmountDetailInfo(settlementId);
            return new CommonResult().success(checkAmountDetailInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new CommonResult().failed();
        }
    }

    /**
     * 获取对账单明细-分页
     *
     * @return
     */
    @GetMapping(value = "/checkAmountList")
    public Object checkAmountList(FinanceCheckAccount financeCheckAccount, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        try {
            return new CommonResult().success(financeCheckAccountService.page(new Page<>(pageNum, pageSize), new QueryWrapper<>(financeCheckAccount)));
        } catch (Exception e) {
            e.printStackTrace();
            return new CommonResult().failed();
        }

    }
}

